﻿#Region "   Imports"

Imports System.Text
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System.ComponentModel

#End Region

#Region "   MenuModifiedStrip"

''' <summary>
''' MenuModifiedStrip Class
''' </summary>
''' <remarks>Version 1.0.0</remarks>
<ToolboxItem(True), ToolboxBitmap(GetType(MenuModifiedStrip), "MenuModifiedStrip.MenuModifiedStrip.bmp"), ToolboxItemFilter("System.Windows.Forms"), Description("Display the MenuStrip.")> _
Public Class MenuModifiedStrip
    Inherits MenuStrip
    ''' <summary>
    ''' Constructor of MenuModifiedStrip
    ''' </summary>
    Public Sub New()
        InitializeComponent()
    End Sub
    ''' <summary>
    ''' Initialize MenuModifiedStrip and MenuRenderer Class
    ''' </summary>
    Public Sub InitializeComponent()
        Me.Name = "MenuModifiedStrip"
        Me.Renderer = New yMenuRenderer()
    End Sub

End Class
''' <summary>
''' MenuRenderer Class for MenuModifiedStrip
''' </summary>
''' <remarks>Version 1.0</remarks>
Public Class yMenuRenderer
    Inherits ToolStripProfessionalRenderer
    Dim R0 As Int32 = 255, G0 As Int32 = 214, B0 As Int32 = 78
    Public StrokeColor As Color = Color.FromArgb(196, 177, 118)
    ''' <summary>
    ''' Draw MenuItem Background of MenuModifiedStrip
    ''' </summary>
    Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        If e.Item.Selected Then
            Dim g As Graphics = e.Graphics
            g.SmoothingMode = SmoothingMode.HighQuality
            Dim pa As GraphicsPath = New GraphicsPath()
            Dim rect As Rectangle = New Rectangle(2, 1, e.Item.Size.Width - 2, e.Item.Size.Height - 1)
            DrawArc(rect, pa)
            Dim lgbrush As LinearGradientBrush = New LinearGradientBrush(rect, Color.White, Color.White, LinearGradientMode.Vertical)
            Dim pos As Single() = New Single(3) {0.0F, 0.4F, 0.45F, 1.0F}
            Dim colors As Color() = New Color(3) {GetColor(0, 50, 100), GetColor(0, 0, 30), Color.FromArgb(R0, G0, B0), GetColor(0, 50, 100)}
            Dim mix As ColorBlend = New ColorBlend()
            mix.Colors = colors
            mix.Positions = pos
            lgbrush.InterpolationColors = mix
            g.FillPath(lgbrush, pa)
            g.DrawPath(New Pen(StrokeColor), pa)
            lgbrush.Dispose()
        Else
            MyBase.OnRenderMenuItemBackground(e)
        End If
    End Sub

    Dim offsetx As Int32 = 3, offsety As Int32 = 2, imageheight As Int32 = 0, imagewidth As Int32 = 0
    ''' <summary>
    ''' Draw ItemImage for MenuModifiedStrip
    ''' </summary>
    Protected Overrides Sub OnRenderItemImage(ByVal e As System.Windows.Forms.ToolStripItemImageRenderEventArgs)
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
        If Not (e.Image Is Nothing) Then
            imageheight = e.Item.Height - offsety * 2
            imagewidth = ((Convert.ToDouble(imageheight) / e.Image.Height) * e.Image.Width)
        End If
        e.Graphics.DrawImage(e.Image, New Rectangle(offsetx, offsety, imagewidth, imageheight))
    End Sub

#Region "Paint Method"

    Private _radius As Int32 = 6
    ''' <summary>
    ''' Draw Arc around MenuItem of MenuModifiedStrip
    ''' </summary>
    ''' <param name="re">Rectangle</param>
    ''' <param name="pa">Graphics Pth</param>
    Public Sub DrawArc(ByVal re As Rectangle, ByVal pa As GraphicsPath)
        Dim _radiusX0Y0 As Int32 = _radius, _radiusXFY0 As Int32 = _radius, _radiusX0YF As Int32 = _radius, _radiusXFYF As Int32 = _radius
        pa.AddArc(re.X, re.Y, _radiusX0Y0, _radiusX0Y0, 180, 90)
        pa.AddArc(re.Width - _radiusXFY0, re.Y, _radiusXFY0, _radiusXFY0, 270, 90)
        pa.AddArc(re.Width - _radiusXFYF, re.Height - _radiusXFYF, _radiusXFYF, _radiusXFYF, 0, 90)
        pa.AddArc(re.X, re.Height - _radiusX0YF, _radiusX0YF, _radiusX0YF, 90, 90)
        pa.CloseFigure()
    End Sub
    ''' <summary>
    ''' Color used for Rendering MenuModifiedStrip
    ''' </summary>
    ''' <param name="R">Red Value</param>
    ''' <param name="G">Green Value</param>
    ''' <param name="B">Blue Value</param>
    ''' <returns></returns>
    ''' <remarks>New Color</remarks>
    Public Function GetColor(ByVal R As Int32, ByVal G As Int32, ByVal B As Int32) As Color
        If (R + R0 > 255) Then R = 255 Else R = R + R0
        If (G + G0 > 255) Then G = 255 Else G = G + G0
        If (B + B0 > 255) Then B = 255 Else B = B + B0
        Return Color.FromArgb(R, G, B)
    End Function

#End Region

End Class

#End Region






